package com.hzhr.iot.device.controller;

import com.hzhr.iot.core.annotation.ApiImplicitInternalParams;
import com.hzhr.iot.core.annotation.Author;
import com.hzhr.iot.core.dto.ResponseExceptionDto;
import com.hzhr.iot.core.exception.ServiceException;
import com.hzhr.iot.device.controller.base.BaseController;
import com.hzhr.iot.device.model.concentrator_command.Concentrator_CommandGetModel;
import com.hzhr.iot.device.model.concentrator_commandSend.Concentrator_CommandSendGetModel;
import com.hzhr.iot.device.model.concentrator_commandSend.Concentrator_CommandSendPostModel;
import com.hzhr.iot.device.service.Concentrator_CommandSendService;
import com.hzhr.iot.device.service.Concentrator_CommandService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Map;

@Api(tags = "Concentrator_CommandSend", description = "集中器的指令推送")
@RestController
@RequestMapping(value = "")
public class Concentrator_CommandSendController extends BaseController {
    @Autowired
    Concentrator_CommandSendService concentrator_commandSendService;

    //region /concentrators/{concentratorId}/command-sends POST
    //region swagger响应码 : post
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功"),
            @ApiResponse(code = 403, message = "----异常代码 : 201  \n----异常类型 : 业务流程异常  \n----异常业务 : 查询集中器  \n----异常说明 : 集中器不存在  \n\n", response = ResponseExceptionDto.class),
    })
    //endregion
    //region swagger说明 : post
    @ApiOperation(value="向集中器推送指令", notes="向集中器推送指令  \n步骤 :  \n1. 查询集中器 :  \n根据路径参数concentratorId查询IotDeviceEntity对象concentrator_1，查询规则如下：  \n          IotDeviceEntity.id = 路径参数concentratorId；  \n          IotDeviceEntity.isValid = '1'；  \n如果concentrator_1不存在，抛出异常201；  \n2. 发送指令  \n3. 返回信息  \n创建结果对象并返回；  \n",produces = "application/json")
    //endregion
    //region swagger参数 : post
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),

            @ApiImplicitParam(name = "concentratorId", value = "集中器编号",required = true, dataType = "int", paramType = "path"),

            @ApiImplicitParam(name = "protocolId", value = "协议编号",required = false, defaultValue = "2", dataType = "int", paramType = "query"),

    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),

            @ApiImplicitParam(name = "_protocolId", value = "协议编号",required = false, defaultValue = "2", dataType = "int", paramType = "query"),

    })
    //endregion
    //region 请求 : post
    @RequestMapping(value = "/concentrators/{concentratorId}/command-sends", method = RequestMethod.POST)
    //endregion
    @Author
    public ResponseEntity<Concentrator_CommandSendGetModel> post(@PathVariable("concentratorId") Integer concentratorId,
                                                                 @RequestParam @ApiIgnore Map<String, Object> query,
                                                                 @RequestBody Concentrator_CommandSendPostModel body) throws ServiceException {
        Concentrator_CommandSendGetModel responseBody = concentrator_commandSendService.post(initHeader(), concentratorId, query, body);
        return new ResponseEntity<>(responseBody, HttpStatus.OK);
        //endregion
    }
    //endregion

}















































































































































































































































































































































































































































































































































































































